package cn.iocoder.yudao.module.xkfz.service.clinicalHealthCare.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.module.xkfz.domain.entity.basic.IndicatorTree;
import cn.iocoder.yudao.module.xkfz.domain.entity.clinicalHealthCare.ElementData;
import cn.iocoder.yudao.module.xkfz.domain.entity.rules.ScoreCalculationData;
import cn.iocoder.yudao.module.xkfz.domain.entity.talentEchelon.TalentEchelon;
import cn.iocoder.yudao.module.xkfz.domain.excel.entity.PlatformConstruction;
import cn.iocoder.yudao.module.xkfz.mapper.basic.IndicatorTreeMapper;
import cn.iocoder.yudao.module.xkfz.mapper.clinicalHealthCare.ElementDataMapper;
import cn.iocoder.yudao.module.xkfz.mapper.clinicalHealthCare.PlatformConstructionMapper;
import cn.iocoder.yudao.module.xkfz.mapper.talentEchelon.TalentEchelonMapper;
import cn.iocoder.yudao.module.xkfz.service.clinicalHealthCare.ClinicalHealthCareService;
import cn.iocoder.yudao.module.xkfz.service.reporting.ScoreCalculationService;
import cn.iocoder.yudao.module.xkfz.service.reporting.impl.ScoreCalculationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 临床医疗
 */
@Service
public class ClinicalHealthCareServiceImpl implements ClinicalHealthCareService {

    @Autowired
    ScoreCalculationService scoreCalculationService;
    @Autowired
    ElementDataMapper elementDataMapper;
    @Autowired
    PlatformConstructionMapper platformConstructionMapper;
    @Autowired
    IndicatorTreeMapper indicatorTreeMapper;



    @Override
    public Boolean importClinicalHealthCare(List<ElementData> list, String year, String indicatorId) {

        //分类，求每个科室，每一个类型的排序
        List<ScoreCalculationData> scoreCalculationDataList = elementDataMapper.queryElementByType(year);
        //计算规则
        scoreCalculationService.selectionRule(indicatorId, year, scoreCalculationDataList);
        return null;
    }

    /**
     * 国家、省级医疗服务平台建设情况导入模版接口
     * @param list
     * @param year
     * @param indicatorName
     * @return
     */
    @Override
    public Boolean importPlatformConstruction(List<PlatformConstruction> list, String year, String indicatorName) {
      if (CollectionUtil.isNotEmpty(list)) {
          //插入年份
          list.stream().forEach(res -> {
              res.setYear(year);
          });
      }
      //删除原来数据库的数据
      platformConstructionMapper.delete(PlatformConstruction::getYear,year);
      //新增导入的数据
      platformConstructionMapper.insertBatch(list);
      //新增完以后，同时进行分数计算
      IndicatorTree indicatorTree = indicatorTreeMapper.selectOne("INDICATOR_NAME", indicatorName);
      //分类，求每个科室，每一个类型的个数
      List<ScoreCalculationData> scoreCalculationData = platformConstructionMapper.queryPlatformConstructionByType(year);
      scoreCalculationService.selectionRule(String.valueOf(indicatorTree.getId()), year, scoreCalculationData);
      return true;
    }

}
